from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-05 14:02:03.747366
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 05, Mar, 2022
Time: 14:02:08
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.3878
Nobs: 586.000 HQIC: -48.7978
Log likelihood: 6980.95 FPE: 4.94018e-22
AIC: -49.0595 Det(Omega_mle): 4.24234e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351365 0.067742 5.187 0.000
L1.Burgenland 0.107860 0.041143 2.622 0.009
L1.Kärnten -0.110656 0.021471 -5.154 0.000
L1.Niederösterreich 0.191079 0.085921 2.224 0.026
L1.Oberösterreich 0.122978 0.084857 1.449 0.147
L1.Salzburg 0.257885 0.043576 5.918 0.000
L1.Steiermark 0.036604 0.057553 0.636 0.525
L1.Tirol 0.101950 0.046462 2.194 0.028
L1.Vorarlberg -0.068500 0.040967 -1.672 0.095
L1.Wien 0.016633 0.075450 0.220 0.826
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051864 0.145786 0.356 0.722
L1.Burgenland -0.037752 0.088544 -0.426 0.670
L1.Kärnten 0.041800 0.046208 0.905 0.366
L1.Niederösterreich -0.204352 0.184909 -1.105 0.269
L1.Oberösterreich 0.458289 0.182619 2.510 0.012
L1.Salzburg 0.282417 0.093779 3.012 0.003
L1.Steiermark 0.113590 0.123859 0.917 0.359
L1.Tirol 0.304564 0.099990 3.046 0.002
L1.Vorarlberg 0.026130 0.088164 0.296 0.767
L1.Wien -0.027426 0.162375 -0.169 0.866
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200281 0.034557 5.796 0.000
L1.Burgenland 0.088675 0.020989 4.225 0.000
L1.Kärnten -0.007261 0.010953 -0.663 0.507
L1.Niederösterreich 0.240030 0.043831 5.476 0.000
L1.Oberösterreich 0.161046 0.043288 3.720 0.000
L1.Salzburg 0.040153 0.022230 1.806 0.071
L1.Steiermark 0.025935 0.029360 0.883 0.377
L1.Tirol 0.081948 0.023702 3.457 0.001
L1.Vorarlberg 0.053718 0.020899 2.570 0.010
L1.Wien 0.117589 0.038490 3.055 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119555 0.034544 3.461 0.001
L1.Burgenland 0.042564 0.020981 2.029 0.042
L1.Kärnten -0.013092 0.010949 -1.196 0.232
L1.Niederösterreich 0.170945 0.043815 3.902 0.000
L1.Oberösterreich 0.337611 0.043272 7.802 0.000
L1.Salzburg 0.099946 0.022221 4.498 0.000
L1.Steiermark 0.110378 0.029349 3.761 0.000
L1.Tirol 0.089778 0.023693 3.789 0.000
L1.Vorarlberg 0.060495 0.020891 2.896 0.004
L1.Wien -0.018480 0.038475 -0.480 0.631
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124766 0.065009 1.919 0.055
L1.Burgenland -0.044720 0.039484 -1.133 0.257
L1.Kärnten -0.045383 0.020605 -2.202 0.028
L1.Niederösterreich 0.135294 0.082456 1.641 0.101
L1.Oberösterreich 0.162395 0.081434 1.994 0.046
L1.Salzburg 0.284601 0.041819 6.806 0.000
L1.Steiermark 0.058212 0.055232 1.054 0.292
L1.Tirol 0.157344 0.044588 3.529 0.000
L1.Vorarlberg 0.096964 0.039315 2.466 0.014
L1.Wien 0.073635 0.072407 1.017 0.309
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079399 0.050681 1.567 0.117
L1.Burgenland 0.024692 0.030781 0.802 0.422
L1.Kärnten 0.053259 0.016064 3.315 0.001
L1.Niederösterreich 0.188688 0.064282 2.935 0.003
L1.Oberösterreich 0.333036 0.063485 5.246 0.000
L1.Salzburg 0.033953 0.032601 1.041 0.298
L1.Steiermark 0.006718 0.043058 0.156 0.876
L1.Tirol 0.119310 0.034760 3.432 0.001
L1.Vorarlberg 0.065311 0.030649 2.131 0.033
L1.Wien 0.097555 0.056448 1.728 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170812 0.061171 2.792 0.005
L1.Burgenland 0.005427 0.037153 0.146 0.884
L1.Kärnten -0.065905 0.019389 -3.399 0.001
L1.Niederösterreich -0.106757 0.077587 -1.376 0.169
L1.Oberösterreich 0.208852 0.076626 2.726 0.006
L1.Salzburg 0.053975 0.039350 1.372 0.170
L1.Steiermark 0.247609 0.051971 4.764 0.000
L1.Tirol 0.499501 0.041955 11.906 0.000
L1.Vorarlberg 0.064254 0.036993 1.737 0.082
L1.Wien -0.074543 0.068132 -1.094 0.274
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161246 0.067859 2.376 0.017
L1.Burgenland -0.002071 0.041215 -0.050 0.960
L1.Kärnten 0.062925 0.021509 2.926 0.003
L1.Niederösterreich 0.166078 0.086070 1.930 0.054
L1.Oberösterreich -0.054973 0.085004 -0.647 0.518
L1.Salzburg 0.208271 0.043652 4.771 0.000
L1.Steiermark 0.138472 0.057653 2.402 0.016
L1.Tirol 0.055645 0.046542 1.196 0.232
L1.Vorarlberg 0.146802 0.041038 3.577 0.000
L1.Wien 0.120719 0.075581 1.597 0.110
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392424 0.039851 9.847 0.000
L1.Burgenland -0.004472 0.024204 -0.185 0.853
L1.Kärnten -0.021147 0.012631 -1.674 0.094
L1.Niederösterreich 0.200085 0.050545 3.959 0.000
L1.Oberösterreich 0.230953 0.049919 4.627 0.000
L1.Salzburg 0.037081 0.025635 1.447 0.148
L1.Steiermark -0.017018 0.033857 -0.503 0.615
L1.Tirol 0.090429 0.027332 3.309 0.001
L1.Vorarlberg 0.050715 0.024100 2.104 0.035
L1.Wien 0.043699 0.044385 0.985 0.325
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036596 0.103021 0.168219 0.137662 0.095241 0.080490 0.031884 0.209011
Kärnten 0.036596 1.000000 -0.027760 0.131667 0.048268 0.084848 0.443707 -0.067206 0.089278
Niederösterreich 0.103021 -0.027760 1.000000 0.310894 0.118108 0.270134 0.065372 0.151118 0.288371
Oberösterreich 0.168219 0.131667 0.310894 1.000000 0.212427 0.294518 0.166227 0.135341 0.235727
Salzburg 0.137662 0.048268 0.118108 0.212427 1.000000 0.121946 0.090933 0.104412 0.123036
Steiermark 0.095241 0.084848 0.270134 0.294518 0.121946 1.000000 0.133987 0.105796 0.033048
Tirol 0.080490 0.443707 0.065372 0.166227 0.090933 0.133987 1.000000 0.062917 0.151122
Vorarlberg 0.031884 -0.067206 0.151118 0.135341 0.104412 0.105796 0.062917 1.000000 -0.005078
Wien 0.209011 0.089278 0.288371 0.235727 0.123036 0.033048 0.151122 -0.005078 1.000000